package com.exam.action;

import java.util.Map;

import org.apache.struts2.interceptor.ApplicationAware;

import com.exam.model.SettingModel;
import com.opensymphony.xwork2.Preparable;
public class SettingAction implements ApplicationAware,Preparable{
	
	private int type=0;  //切换按钮的类型 0/1
	private String copyright;
	private int pageSize; //分页数
	private SettingModel setting;
	
	public String isOpenErrQue(){
		setting.setIsOpenErrQue(type);
		return "success";
	}
	public String isRegister(){
		setting.setIsRegister(type);
		return "success";
	}
	
	/**
	 * 保存设置到 application
	 * @return
	 */
	public String save(){
		setting.setPageSize(pageSize);
		setting.setCopyright(copyright);
		return "success";
	}
	
	Map<String, Object> application;
	public void setApplication(Map<String, Object> app) {
		this.application = app;
	}
	public int getType() {
		return type;
	}
	public void setType(int type) {
		this.type = type;
	}
	public String getCopyright() {
		return copyright;
	}

	public void setCopyright(String copyright) {
		this.copyright = copyright;
	}

	public int getPageSize() {
		return pageSize;
	}

	public void setPageSize(int pageSize) {
		this.pageSize = pageSize;
	}

	/**
	 * 预处理
	 */
	public void prepare() throws Exception {
		System.out.println("加载application中的设置...");
		if(type!=1){
			type=0;
		}
		setting = (SettingModel) this.application.get("SYS_SETTING");
	}
	
}
